package uk.ac.ebi.bioinvindex.dao.ejb3;

import org.hibernate.criterion.Restrictions;
import uk.ac.ebi.bioinvindex.dao.AnnotatableDAO;
import uk.ac.ebi.bioinvindex.model.impl.AnnotatableImpl;

import javax.persistence.EntityManager;

/**
 * User: Nataliya Sklyar (nsklyar@ebi.ac.uk)
 * Date: Nov 22, 2007
 */
public class AnnotatableEJB3DAO<T extends AnnotatableImpl>
		extends IdentifiableEJB3DAO <T>
		implements AnnotatableDAO<T> {

	protected AnnotatableEJB3DAO() {
	}

	protected AnnotatableEJB3DAO(Class<T> persistentClass) {
		super(persistentClass);
	}

	public AnnotatableEJB3DAO(Class<T> persistentClass, EntityManager entityManager) {
		super(persistentClass, entityManager);
	}

	public T getByAcc(String acc) {
		Class<T> clazz = getPersistentClass();
		return (T) getSession().createCriteria(clazz)
					.add(Restrictions.eq("acc", acc))
					.uniqueResult();
	}
}
